package com.wfyn.reggie.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wfyn.reggie.common.web.base.BaseController;
import com.wfyn.reggie.common.web.domain.Result;
import com.wfyn.reggie.modules.sys.domain.Employee;
import com.wfyn.reggie.modules.sys.param.PageListRequest;
import com.wfyn.reggie.modules.sys.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;



/**
 * 员工管理
 * @author wfyn
 * @date 2023/9/25
 */

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController extends BaseController {

    @Resource
    EmployeeService employeeService;

    /**
     * 员工登录
     * @param employee 员工JSON，含有 username,password
     * @return {@link Result}
     */
    @PostMapping("/login")
    public Result<Employee> login( @RequestBody Employee employee) {
        return employeeService.login(employee);
    }

    /**
     * 员工退出
     * @return
     */
    @PostMapping("/logout")
    public Result<String> logout()
    {

      return employeeService.logout() ;
    }

    /**
     * 新增员工
     * @param employee 员工信息
     * @return
     */
    @PostMapping
    public Result<String> saveEmployee(@RequestBody Employee employee)
    {


        return   employeeService.saveEmployee(employee);
    }

    /**
     * 分页查询员工列表
     * @param pageListRequest 查询条件
     * @return
     */
   @GetMapping("/page")
    public Result<Page<Employee>> pageList( PageListRequest pageListRequest)
    {
        return  employeeService.pageList(pageListRequest);
    }

    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    @PutMapping
    public Result<String> updateEmployee(@RequestBody Employee employee)
    {
        return  employeeService.updateEmployee(employee);
    }

    /**
     *  根据获取员工具体信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<Employee> getEmployee(@PathVariable Integer id)
    {

        return employeeService.getEmployeeById(id);
    }

    /**
     * 根据id删除员工
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<String> deleteEmployee(@PathVariable Integer id)
    {

        employeeService.removeById(id);

        return Result.success();

    }






}
